package article;

import java.util.*;
import javax.jdo.annotations.*;
import response.*;
import com.google.appengine.api.datastore.Key;
import course.*;

@PersistenceCapable
public class Article {
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key artId;
	
	@Persistent
	private Course courseId;
	
	@Persistent
	private String artMem;
	
	@Persistent
	private String artTitle;
	
	@Persistent
	private String pubDate;
	
	@Persistent
	private String artContent;
	
	@Persistent
	private int artGood;
	
	@Persistent
	private int artBad;
	
	@Persistent(mappedBy = "artId")
	@Element(dependent = "true") 
	private List <Response> res;

	public Article(Course course,String member,String title,String pub_time,String content){
		this.courseId = course;
		this.artMem = member;
		this.artTitle = title;
		this.pubDate = pub_time;
		this.artContent = content;
		this.artGood = 0;
		this.artBad = 0;
	}
	
	public Article(){
		this.artTitle = "NA";
		this.artContent = "NA";
		this.artGood = 0;
		this.artBad = 0;
	}
	
	public Long getId(){
		return artId.getId();
	}
	
	public Course getCourse(){
		return courseId;
	}
	
	public String getMember(){
		return artMem;
	}
	
	public String getTitle(){
		return artTitle;
	}
	
	public String getDate(){
		return pubDate;
	}
	
	public String getCont(){
		return artContent;
	}
	
	public int getGood(){
		return artGood;
	}
	
	public int getBad(){
		return artBad;
	}
	
	public void setTitle(String newTitle){
		this.artTitle = newTitle;
	}
	
	public void setCont(String newCont){
		this.artContent = newCont;
	}
	
	public void setGood(){
		this.artGood++;
	}
	
	public void setBad(){
		this.artBad++;
	}
	
	public List<Response> getAllRes(){
		List<Response> temp = new ArrayList<Response>();
		for(Response re : this.res){
			temp.add(re);
		}
		return temp;
	}
	
	public void addRe(Article article,String cont,String pub_time,String responser){
		res.add(new Response(article,cont,pub_time,responser));
	}
}
